package com.example.book_libapp;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class BookCommentAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;

	public BookCommentAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.book_commentitem, null);

		TextView user = (TextView) vi.findViewById(R.id.user); // user
		TextView date = (TextView) vi.findViewById(R.id.date); // date
		TextView commentview = (TextView) vi.findViewById(R.id.comment); // book
		TextView ownerstat = (TextView) vi.findViewById(R.id.owner); // book

		RatingBar RatingBarBook = (RatingBar) vi
				.findViewById(R.id.ratingbar_Small1);

		HashMap<String, String> comment = new HashMap<String, String>();
		comment = data.get(position);

		user.setText(comment.get(BookDetails.TAG_CREBY));
		date.setText(comment.get(BookDetails.TAG_CREAT));
		commentview.setText(comment.get(BookDetails.TAG_CREVIEW));
		ownerstat.setText(comment.get(BookDetails.TAG_OWNER).toString());
		ownerstat.setVisibility(View.GONE);
		
		RatingBarBook.setRating(Float.parseFloat(comment
				.get(BookDetails.TAG_CRATE)));

		return vi;

	}
}